/* app003-window.c
 *
 * Copyright 2024 wan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "app003-config.h"
#include "app003-window.h"

struct _App003Window
{
  GtkApplicationWindow  parent_instance;

  /* Template widgets */
  GtkHeaderBar        *header_bar;
  GtkBox            *my_box;
  GtkButton *btn_ok;
  GtkMenu *my_menu;
  GtkMenuItem *update;
  GtkMenuItem *add;
};

G_DEFINE_TYPE (App003Window, app003_window, GTK_TYPE_APPLICATION_WINDOW)

static void
app003_window_class_init (App003WindowClass *klass)
{
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  gtk_widget_class_set_template_from_resource (widget_class, "/a/b/c/app003-window.ui");
  gtk_widget_class_bind_template_child (widget_class, App003Window, header_bar);
  gtk_widget_class_bind_template_child (widget_class, App003Window, my_box);
  gtk_widget_class_bind_template_child (widget_class, App003Window, btn_ok);
  gtk_widget_class_bind_template_child (widget_class, App003Window, my_menu);
  gtk_widget_class_bind_template_child (widget_class, App003Window, update);
  gtk_widget_class_bind_template_child (widget_class, App003Window, add);
}
GtkMenu *mymenu;
gboolean click_menu(GdkEventButton *event){
    //g_return_val_if_fail(view != NULL, FALSE);
    //g_return_val_if_fail(GTK_IS_MENU(data), FALSE);
    g_return_val_if_fail(event != NULL, FALSE);
  g_print("button..\n");
  gtk_widget_show_all((GtkWidget *)mymenu);
   gtk_menu_popup_at_pointer(GTK_MENU(mymenu), (GdkEvent *)event);
  g_print("button2..\n");
  return FALSE;
}

static void
app003_window_init (App003Window *self)
{

  
  gtk_widget_init_template (GTK_WIDGET (self));
  mymenu = self->my_menu;

  
  
  //设置背景色 有问题？？？
/* GtkCssProvider *provider = gtk_css_provider_new(); */
/* GdkDisplay *display = gdk_display_get_default(); */
/* GdkScreen *screen = gdk_display_get_default_screen(display); */
/* gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); */

/* gtk_css_provider_load_from_path(provider, "my.css", NULL); */
  
  
  //设置背景图
  //GtkWidget*image = gtk_image_new_from_file ("./add.png");
  ////gtk_button_set_image (self->btn_ok,  image);
  //gtk_button_set_relief(GTK_BUTTON(self->btn_ok), GTK_RELIEF_NONE);
  //gtk_widget_show (image);
  // 
  g_signal_connect (self->btn_ok, "clicked", G_CALLBACK(click_menu), self->my_menu);
  
}
